package de.fhaugsburg.games.boardgames;


public enum ManhattanDirection {
	DOWN (1, 0),
	UP (-1, 0),
	RIGHT (0, 1),
	LEFT (0, -1);
	
	public GridPoint gridPoint;
	
	/**
	 * private constructor, only called by the factory method
	 * @param row
	 * @param column
	 */
	private ManhattanDirection (int row, int column){
		this.gridPoint = new GridPoint(row, column);
	}
	
	
	
	/**
	 * calculate the direction
	 * @param a
	 * @param b
	 * @return
	 */
	public static ManhattanDirection calcDir(GridPoint a, GridPoint b){
		if (a.equals(b)) return null;
		//horizontal
		if (a.getRow() == b.getRow()){
			if (a.getColumn() > b.getColumn()){
				return LEFT;
			}else{
				return RIGHT;
			}
		//vertical	
		}else if (a.getColumn() == b.getColumn()){
			if (a.getRow() > b.getRow()){
				return UP;
			}else{
				return DOWN;
			}
		}else{
			return null;
		}
	}

	/**
	 * rotate direction 90 degrees, clockwise
	 * @return
	 */
	public ManhattanDirection orthogonalDir(){
		if (this == LEFT) return UP;
		if (this == UP) return RIGHT;
		if (this == RIGHT) return DOWN;
		if (this == DOWN) return LEFT;
		throw new RuntimeException("unexpected error, please update your program");
	}
	
	
}
